﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Services;
using Domen;
using Sesija;

namespace LFSSignature
{
    /// <summary>
    /// Summary description for LFSServis
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class LFSServis : System.Web.Services.WebService
    {
        BrokerLFS brokerLFS = BrokerLFS.GetInstance();
        Driver vozac = new Driver();


        [WebMethod]
        public void KreiranjeSlikeServis(Driver driver)
        {
            //D:\Visual Studio 2012\ASP\LFSStatistika\LFSStatistika\Slike\LFSSignature.gif            
            //D:\\Visual Studio 2012\\ASP\\LFSStatistika\\WebAppServis\\LFSStatistika\\Slike\\LFSSignature.gif

            vozac = driver;
            Bitmap image = new Bitmap(Server.MapPath(@"~\Slike\LFSSignature.gif"));
            Bitmap imgTemp = new Bitmap(image);
            Bitmap image3 = new Bitmap(brokerLFS.CreateImage(vozac, imgTemp));

            using (var ms = new MemoryStream())
            {
                image3.Save(ms, ImageFormat.Gif);
                var imgF = Bitmap.FromStream(ms);

                //imgF.Save(Server.MapPath(@"~\SlikeServis\" + driver.Username + "lfs.gif"));
                imgF.Save(Server.MapPath(@"~\SlikeUser\" + vozac.Username + "lfs.gif"));
                //string server2 = HttpContext.Current.Server.MapPath(@"~\SlikeServis\" + vozac.Username + "lfs.gif");
                imgF.Dispose();
            }
            string imgUrl = Context.Server.MapPath(@"~\SlikeUser\");
            imgUrl = Context.Server.MapPath(@"~\SlikeUser\" + vozac.Username + "lfs.gif");

            vozac = driver;
            ThreadStart ts = NovKorisnik;
            Thread nit = new Thread(ts);
            nit.Start();

        }

        public void NovKorisnik()
        {
            while (true)
            {
                Thread.Sleep(6000);
                Bitmap image = new Bitmap(Server.MapPath(@"~\Slike\LFSSignature.gif"));
                Bitmap imgTemp = new Bitmap(image);
                Bitmap image3 = new Bitmap(brokerLFS.CreateImage(vozac, imgTemp));

                using (var ms = new MemoryStream())
                {
                    image3.Save(ms, ImageFormat.Gif);
                    var imgF = Bitmap.FromStream(ms);

                    //imgF.Save(Server.MapPath(@"~\SlikeServis\" + driver.Username + "lfs.gif"));
                    imgF.Save(Server.MapPath(@"~\SlikeUser\" + vozac.Username + "lfs.gif"));
                    //string server2 = HttpContext.Current.Server.MapPath(@"~\SlikeServis\" + vozac.Username + "lfs.gif");
                    imgF.Dispose();
                }
                string imgUrl = Context.Server.MapPath(@"~\SlikeUser\");
                imgUrl = Context.Server.MapPath(@"~\SlikeUser\" + vozac.Username + "lfs.gif");
            }



            //ThreadStart ts2 = RadiStalno;
            //Thread nit2 = new Thread(ts2);
            //nit2.Start();


        }
    }
}
